package cn.dengta.webapp.push.vo;

import java.util.Date;
import java.util.EnumMap;

import cn.dengta.common.model.Bean;
import cn.dengta.context.model.ImI18nKey;
import cn.dengta.context.model.Language;
import cn.dengta.webapp.push.dto.GiftDTO;
import cn.dengta.webapp.push.dto.UserDTO;
import cn.dengta.webapp.trade.entity.GiftLog;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 电视墙 数据载体
 */
@Getter
@Setter
@Accessors(chain = true)
public class TvWallVO implements Bean<Long> {

	protected Long id;
	protected UserDTO user;
	protected UserDTO to;
	protected GiftDTO gift;
	/** 电视墙类型：1=普通；2=锁屏 */
	protected Integer type;
	protected Date time;
	/** 停留（锁屏）时间（秒） */
	protected Integer stayTime;

	public TvWallVO() {
	}

	public TvWallVO(GiftLog log) {
		this.id = log.getId();
		this.user = new UserDTO(log.getSendUserId(), log.getSendUserNickname(), log.getSendUserAvatar());
		this.to = new UserDTO(log.getToUserId(), log.getToUserNickname(), log.getToUserAvatar());
		this.gift = new GiftDTO(log.getGiftId(), log.getGiftName(), log.getGiftIcon(), log.getGiftNum(), log.getTotalCoin());
		this.type = log.getType();
		this.time = log.getAddTime();
		this.stayTime = log.getStayTime();
	}

	public void setId(Long id) {
		this.id = id;
	}

	public static EnumMap<Language, TvWallVO> of(GiftLog log) {
		EnumMap<Language, TvWallVO> map = new EnumMap<>(Language.class);
		for (Language language : Language.CACHE) {
			TvWallVO vo = new TvWallVO();
			vo.setId(log.getId());
			// 神秘人的国际化处理
			String anonymousName = language.msg(ImI18nKey.MYSTERIOUS_MAN);
			String sendUserNickname = log.isAnonymous(true) ? anonymousName : log.getSendUserNickname();
			String toUserNickname = log.isAnonymous(false) ? anonymousName : log.getToUserNickname();
			vo.setUser(new UserDTO(log.getSendUserId(), sendUserNickname, log.getSendUserAvatar()));
			vo.setTo(new UserDTO(log.getToUserId(), toUserNickname, log.getToUserAvatar()));
			//
			vo.setGift(new GiftDTO(log.getGiftId(), language.msg(log.getGiftName()), log.getGiftIcon(), log.getGiftNum(), log.getTotalCoin()));
			vo.setType(log.getType());
			vo.setTime(log.getAddTime());
			vo.setStayTime(log.getStayTime());
			map.put(language, vo);
		}
		return map;
	}

}
